package server.command.receive;

import com.ita.project1.dao.impl.DepartmentDaoImpl;

import common.entity.Department;
import common.entity.Indicator;
import server.resp.send.Resp;

public class AddDepartmentCommand extends Command{
	
	private Department department;
	
	@Override
	public Resp execute() {
		int count = addDepartment();
		Resp resp = new Resp(Indicator.AD, count);
		return resp;
	}
	
	public int addDepartment() {
		int m = 0;
		String dataStr = this.getCommandValue();
		String[] data = dataStr.split(";");
		String dName = data[0].split(":")[1];
		String city = data[1].split(":")[1];
		department = new Department(dName, city);
		DepartmentDaoImpl daoImpl = new DepartmentDaoImpl();
		m = daoImpl.addDepartment(department);
		return m;
	}
}
